import { DataSetProps } from 'choerodon-ui/pro/lib/data-set/DataSet';
import { FieldType } from 'choerodon-ui/pro/lib/data-set/enum';

import request from 'utils/request';
import { API_HOST } from 'utils/config';

export const TableListDataSetConfig = (): DataSetProps => ({
  autoQuery: false,
  autoCreate: false,
  pageSize: 20,
  paging: true,
  queryFields: [
    { name: 'lineNum', type: FieldType.string, label: '行号', },
    { name: 'wenben1', type: FieldType.string, label: '文本', },
    { name: 'singleMoney', type: FieldType.string, label: '单个金额', },
  ],
  fields: [
    {
      name: 'singleMoney',
      type: FieldType.number,
      label: '单个金额',
      required: true,
    },
    {
      name: 'lineNum',
      type: FieldType.number,
      label: '行号',
    },
    {
      name: 'wenben1',
      type: FieldType.string,
      label: '文本',
    },
  ],
  transport: {
    read: ({ params }) => {
      return {
        url: '/hmde/v1/executor/WYTST_CUSTOM_TEST_LINE1/page',
        method: 'GET',
        params,
      };
    },
    destroy: ({ data }) => {
      return {
        url: '/hmde/v1/executor/WYTST_CUSTOM_TEST_LINE1/batch-delete',
        method: 'DELETE',
        data,
      };
    },
  },
});

export const saveAll = ({ header, body }) => {
  return request(
    `${API_HOST}/hmde/v1/executor/WYTST_CUSTOM_TEST_HEADER1/batch-update`,
    {
      method: 'POST',
      data: body,
      headers: {
        ...header,
      },
    },
  );
};
